package com.star.star.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.star.star.R;
import com.star.star.fragment.BuyListFragment;

import java.util.ArrayList;
import java.util.List;

public class tripActivity extends AppCompatActivity implements View.OnClickListener {
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private List<String> mTitles;
    private MyPagerAdapter mAdapter;
    private String[] strings;
    private List<String> mid;
    private SlidingTabLayout SmartTabLayout;
    private ViewPager vp;
    private TextView tv_main_title,tv_back;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_trip);
        SmartTabLayout =  findViewById(R.id.SmartTabLayout);
        vp = findViewById(R.id.vp);
        tv_back =  findViewById(R.id.tv_back);
        tv_main_title =  findViewById(R.id.tv_main_title);
        tv_main_title.setText("肖战行动");
        tv_back.setOnClickListener(this);
        mTitles = new ArrayList<>();
        mTitles.add("2019年9月");
        mTitles.add("2019年10月");
        mTitles.add("2019年11月");
        mTitles.add("2019年12月");
        strings = new String[mTitles.size()];
        mid = new ArrayList<>();
        mid.add("1");
        mid.add("2");
        mid.add("3");
        mid.add("4");
        mFragments.clear();
        for (int i = 0; i < mTitles.size(); i++) {
            strings[i] = mTitles.get(i);
            mFragments.add(BuyListFragment.getInstance(mid.get(i)));
        }
        mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        vp.setAdapter(mAdapter);
        SmartTabLayout.setViewPager(vp);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_back:
                finish();
                break;
        }
    }
    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles.get(position);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

    }
}
